load("@fbsource//tools/build_defs:cram_test.bzl", "cram_test")
load("@fbsource//tools/build_defs:rust_binary.bzl", "rust_binary")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("sapling")

rust_library(
    name = "xdiff",
    srcs = glob(["src/**/*.rs"]),
    autocargo = {"cargo_toml_config": {
        "lib": {"name": "xdiff"},
        "package": {
            "authors": ["Meta Source Control Team <sourcecontrol-dev@meta.com>"],
            "homepage": "https://sapling-scm.com/",
            "license": "MIT",
            "name": "sapling-xdiff",
            "repository": "https://github.com/facebook/sapling",
        },
    }},
    crate_root = "src/lib.rs",
    deps = [
        "//eden/scm/lib/xdiff-sys:xdiff-sys",
    ],
)

# example binary that uses 'xdiff' library to implement `diff` command
rust_binary(
    name = "diff",
    srcs = ["src/bin/diff.rs"],
    deps = [
        "fbsource//third-party/rust:structopt",
        "//eden/scm/lib/xdiff:xdiff",
    ],
)

# cram tests that use the example binary to test the library
cram_test(
    name = "tests",
    srcs = glob([
        "tests/*.t",
    ]) + [
        "tests/setup.sh",
    ],
    compatible_with = [
        "ovr_config//os:linux",
        "ovr_config//os:macos",
    ],
    env = {
        "XDIFF": "$(location :diff)",
    },
)
